package com.lanchewuyou.user.driver.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lanchewuyou.user.driver.R;
import com.lanchewuyou.user.driver.bean.FourS;

import java.util.ArrayList;
import java.util.List;

/**
 * 4S店搜索框适配器
 */

public class FoursAdapter extends BaseAdapter {
    private List<FourS> fourSList = new ArrayList<>();
    private LayoutInflater inflater;

    public FoursAdapter(List<FourS> fourSList, Context mContext) {
        this.fourSList = fourSList;
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return fourSList.size();
    }

    @Override
    public Object getItem(int position) {
        return fourSList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        FourS fourS = fourSList.get(position);
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.fours_search_item, null);
            viewHolder.foursTitle = (TextView) convertView.findViewById(R.id.fours_search_title);
            viewHolder.foursText = (TextView) convertView.findViewById(R.id.fours_search_address);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.foursTitle.setText(fourS.getName());
        viewHolder.foursText.setText(fourS.getAddress());
        return convertView;
    }

    class ViewHolder {
        public TextView foursTitle;
        public TextView foursText;
    }
}
